package com.work.straighttalk.app;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import butterknife.ButterKnife;

/**
 * Created by dllo on 16/3/1.
 */
public class BaseActivity extends AppCompatActivity {

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
        initView();
    }

    protected void initView() {
    }

    /**
     * Activity间跳转
     *
     * @param targe    要跳转到的页面
     * @param bundle   想要传递的数据
     * @param isFinish if true finish 当前的Activity
     */
    public void startActivity(Class<? extends Activity> targe, Bundle bundle, Boolean isFinish) {
        Intent intent = new Intent();
        intent.setClass(this, targe);
        if (bundle != null)
            intent.putExtra(getPackageName(), bundle);
        startActivity(intent);
        if (isFinish)
            finish();
    }

    /**
     * Activity间的跳转 带返回值
     *
     * @param targe
     * @param bundle
     * @param requestCode
     */
    public void startActivityForResult(Class<? extends Activity> targe, Bundle bundle, int requestCode) {
        Intent intent = new Intent();
        intent.setClass(this, targe);
        if (null != bundle)
            intent.putExtra(getPackageName(), bundle);
        startActivityForResult(intent, requestCode);

    }


    protected final static String NULL = " ";
    private Toast toast;

    /**
     * @param obj 要toast的内容
     */
    public void toast(final Object obj) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (toast == null)
                    toast = Toast.makeText(BaseActivity.this, NULL, Toast.LENGTH_SHORT);
                toast.setText(obj.toString());
                toast.show();
            }
        });
    }
}